home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1988 / Apr 88 / Re- MacApp datafields 4⁄6 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.8 KB  |  63 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  X0501        to MACAPP$
  2.  
  3. Item    2718606                         5-April-88        21:54
  4.  
  5. From:   X0501                           MacApp Developers Assoc, C. Nelson
  6.  
  7. To:     N0658                           ESL, Robert Penland, ASC
  8.  
  9. Sub:    Re: MacApp datafields
  10.  
  11. Robert,
  12.  
  13. The answer to your question is as you have guessed.  The dreaded heap
  14. compaction can and usually does occur between method calls.  I do not know the
  15. exact rules for when it occurs between method calls (Larry, Curt or David?).
  16. What you have shown is dangerous code.
  17.  
  18. The solution to your problem is to either preallcoate the space in a global
  19. structure for n number of DSPCommand Records and keep the index OR allocate the
  20. space on the heap in each TMyRequester’s Init method and then keep a reference
  21. (Pointer) in the object. Allocations made with pointers should be freed by your
  22. own methods or by the free in the object.
  23.  
  24. Here would be my suggested work-around to your problem assuming each
  25. TMyRequester must have its own DSPCommand RECord:
  26.  
  27. PtrDSPCommand = ^DSPCommand;
  28. DSPCommandREC=RECORD
  29.    Command1:INTEGER;
  30.    Command2:INTEGER;
  31.    Command3:Str255;
  32.    END;
  33.  
  34.  then in your CLASS (OBJECT) definition do the following:
  35.  
  36. TMyRequester = TOBJECT(TRequester)
  37.     fDSPCommand: PtrDSPCommand;
  38.     …
  39.     PROCEDURE TMyRequester.IMyRequester;
  40.     PROCEDURE TMyRequester.Free; OVERRIDE;
  41.     …
  42.     END
  43.  
  44. PROCEDURE TMyRequester.IMyRequester;
  45.     VAR myPtr : Ptr;
  46. BEGIN
  47.     myPtr := NewPtr(SIZEOF(DSPCommandREC));
  48.     FailNil(Ptr);
  49.     fDSPCommand := myPtr;
  50. END
  51.  
  52. PROCEDURE TMyRequester.Free;
  53. BEGIN
  54.     DisposPtr(fDSPCommand);
  55.     INHERITED Free;
  56. END
  57.  
  58. OF course I’ve left out all the error handling you would probably want to do if
  59. an allocation fails. or checking if it was OK to free the data.
  60.  
  61.                                 Hope this helps.... Carl
  62.  
  63.